# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class ResUsers(models.Model):
    _inherit = "res.users"

    def _get_fp_user(self):
        return self.env['fp.users'].search(
            [('user_id', '=', self.id)], limit=1)


class FPUsers(models.Model):
    _name = "fp.users"
    _description = "User"

    user_id = fields.Many2one(
        'res.users', string='User', required=True,  index=True,)

    company_id = fields.Many2one(
        'res.company', 'Company', required=True, index=True,
        default=lambda self: self.env.company)

    login = fields.Char(related="user_id.login")
    name = fields.Char(related="user_id.name")

    payee_name = fields.Char(string='收款人', help="当作为用户(开票人)时, 获取对应的收款人和复核人")
    checker_name = fields.Char(string='复核')
    drawer_name = fields.Char(string='开票人')

    taxmachine_id = fields.Many2one(
        'fp.company.taxmachine', 'taxmachine_id',
        domain="[('company_id', '=', company_id)]",
        index=True)

    taxmachine_code = fields.Char(
        string='税控设备编码', related="taxmachine_id.code")

    _sql_constraints = [
        ('user_id_key', 'UNIQUE (user_id)',
         'You can not set two times for the same user !')
    ]
